#include<stdio.h>
int main ()
{
	int n,m;int index=1;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		if(n==0&&m==0)
		{
			break;
		}
		int count=0;
		int a,b;
		for(a=1; a<n; a++)
		{
			for(b=a+1; b<n; b++)
			{
				if((a*a+b*b+m)%(a*b)==0)
				{
					count++;
				}
			}
		}
		printf("Case %d:%d\n",index,count);
		index++;
	}
	return 0;
}
